﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class RandomLevel:Level
{
    public Tag m_3DTagPerfab;
    public GameObject m_BornPartner;
    public GameObject m_BornEnemy1;
    public GameObject m_BornEnemy2;
    public Headquarters m_EnemyTeam;
    public Headquarters m_PartnerTeam;

    protected void Awake()
    {
        GameObject partner = Instantiate(RandomShip());
        GameObject enemy1 = Instantiate(RandomShip());
        GameObject enemy2 = Instantiate(RandomShip());
        var canvas = UtilsUnity.GetCanvas();
        if(canvas)
        {
            var tagEnemy1 = Instantiate(m_3DTagPerfab);
            tagEnemy1.m_NameL.text = "敌人1";
            tagEnemy1.m_BindObj = enemy1;
            var tagEnemy2 = Instantiate(m_3DTagPerfab);
            tagEnemy2.m_NameL.text = "敌人2";
            tagEnemy2.m_BindObj = enemy2;

            tagEnemy1.transform.SetParent(canvas.transform);
            tagEnemy2.transform.SetParent(canvas.transform);


        }

        partner.transform.position = m_BornPartner.transform.position;
        enemy1.transform.position = m_BornEnemy1.transform.position;
        enemy2.transform.position = m_BornEnemy2.transform.position;


        partner.transform.SetParent(m_PartnerTeam.transform);
        enemy1.transform.SetParent(m_EnemyTeam.transform);
        enemy2.transform.SetParent(m_EnemyTeam.transform);

        enemy1.transform.rotation = m_BornEnemy1.transform.rotation;
        enemy2.transform.rotation = m_BornEnemy2.transform.rotation;
    }

    public GameObject RandomShip()
    {
        var perfavShips = ShipManager.Instance.GetAllShipList();
        while(true)
        {
            int index = UnityEngine.Random.Range(0, perfavShips.Count);
            var createObj = perfavShips[index];
            var createShip = createObj.GetComponent<Ship>();
            if (createShip.m_ShipStruct.m_Rank == ShipStruct.ShipRank.RANK_MILITARY)
            {
                return createObj;
            }
        }
    }
}